home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 8 / FM Towns Free Software Collection 8.iso / t_os / bb / src / bb.c next >
Encoding:
C/C++ Source or Header  |  1994-06-01  |  11.0 KB  |  460 lines

  1. /*
  2.     Basie's Browser
  3.         text display from text file
  4.  
  5.                       1993.6.27 v1.0
  6.                       copyright Y.Ouchi
  7.  
  8. */
  9.  
  10. #include    <stdio.h>
  11. #include    <string.h>
  12. #include    <stdlib.h>
  13. #include    <ctype.h>
  14. #include    <register.h>
  15. #include    "egb.h"
  16. #include    "mos.h"
  17. #include    "snd.h"
  18. #include    "bb.h"
  19. #include    "color.h"
  20.  
  21.     /*        関数プロトタイプ宣言                        */
  22.         int        intreal(int, union REGS *, union REGS *, struct SREGS *);
  23. extern    int        textdsp(char *,int,char **,struct logcontent *,short *,int *);
  24. extern    void    linedsp(int, int, char *);
  25. extern    void    box(int, int, int, int, int, int);
  26. extern    int        logcheck ( char *, int, char **, struct logcontent *, short *);
  27. extern    int        titlemod(char *,int,char **,struct logcontent *,short *,int *);
  28. extern    int    ttitlemod(char *,int,char **,struct logcontent *,short *,int *);
  29. extern    void    mesout ( int );
  30. extern    char    *filesel ( void );
  31. extern    void    parmode(struct logcontent *, short *);
  32. extern    void    set24h ( void );
  33.         void    initial ( void );
  34.         void    initial_panel ( void );
  35.  
  36.         char    egbwork[EGBWorkSize];
  37.         char    moswork[MosWorkSize];
  38.         int        max_title;
  39.         int        max_text;
  40.         int        max_content;
  41.         int        max_textn;
  42.         int        max_textp;
  43.         int        dispmode;
  44. static    FILE    *logFp;
  45. static    char    logfile[128]={""};
  46. static    char    *normalmode={"normal"};
  47. static    char    *parentmode={"parent"};
  48.  
  49. void main( int ac, char **av )
  50. {
  51.     char    *file_read_mes={"now file reading"};
  52.     char    *ext_char={".bak"};
  53.     char    *logtext;
  54.     char    **disp_title;
  55.     short    *disptextn;
  56.     short    *disptextp;
  57.     short    *disptext;
  58.     int        i,textno;
  59.     int        contf,back;
  60.     int        ext_ptr;
  61.     int        nowtext;
  62.     char    bupfile[128];
  63.     size_t    logtextleng;
  64.     struct    logcontent    *intext;
  65.     static    int        parmodedone=0;
  66.  
  67.                         /* input log file name check */
  68.     if (ac>=2) {
  69.         strcpy ( logfile, av[1] ) ;
  70.     }
  71.  
  72.                 /* initial display mode (parent mode) set */
  73.     dispmode=PARENT_MODE;
  74.  
  75.                         /* initialize */
  76.     initial();
  77.  
  78.     EGB_writePage(egbwork,1);
  79.     box(390,464,440,478,MODE_BACK_COL,1);
  80.     EGB_color(egbwork, 0, MODE_COL);
  81.     linedsp(391,478,parentmode);
  82.     EGB_writePage(egbwork,0);
  83.     EGB_color(egbwork, 0, TEXT_COL);
  84.  
  85.     if (strlen(logfile)==0) strcpy (logfile,filesel());
  86.  
  87.     while (strlen(logfile)!=0){
  88.  
  89.                         /* log file read */
  90.                             /*  file name separater change */
  91.                             /*  backup file name make (original+.bak) */
  92.         EGB_writePage(egbwork,1);
  93.         box(268,0,639,16,TITLEBACK_COL,1);
  94.         EGB_color(egbwork, 0, TITLE_COL);
  95.         linedsp(268,15,logfile );
  96.         EGB_writePage(egbwork,0);
  97.         ext_ptr=0;
  98.         for (i=0;i<strlen(logfile);i++){
  99.             if (logfile[i]==0x2e) ext_ptr=i;
  100.             if (logfile[i]==0x5c) logfile[i]=0x2f;
  101.         }
  102.         if (ext_ptr==0){
  103.             strcpy(bupfile,logfile);
  104.             strcat(bupfile,ext_char);
  105.         }
  106.         else{
  107.             strncpy(bupfile,logfile,ext_ptr);
  108.             bupfile[ext_ptr]=0x00;
  109.             strcat(bupfile,ext_char);
  110.         }
  111.  
  112.                         /*  memory get and file read */
  113.                         /* memory get for log analize & title display */
  114.  
  115.         (int)logtextleng=_get_file_size(logfile);
  116.  
  117.         if ( (int)logtextleng < 0 ){
  118.             mesout ( FILE_ERROR );
  119.             MOS_end();
  120.             exit(0);
  121.         }
  122.  
  123.         if ( (logtext=malloc(logtextleng+20))==NULL){
  124.             mesout ( MEMORY_ERROR );
  125.             MOS_end();
  126.             exit(0);
  127.         }
  128.         if (logtextleng<100000) logtextleng=100000;
  129.         max_text=logtextleng/500;
  130.         max_content=logtextleng/500;
  131.         max_title=logtextleng/2000;
  132.         if ((intext=malloc(sizeof(int)+sizeof(struct textcontent *)))==NULL ){
  133.             mesout(MEMORY_ERROR);
  134.             MOS_end();
  135.             exit(0);
  136.         }
  137.         if ( (intext->text=malloc(sizeof(union content)*max_content))==NULL ){
  138.             mesout(MEMORY_ERROR);
  139.             MOS_end();
  140.             exit(0);
  141.         }
  142.         if ( (disptextn=malloc(sizeof(short)*max_text))==NULL ){
  143.             mesout(MEMORY_ERROR);
  144.             MOS_end();
  145.             exit(0);
  146.         }
  147.         if ( (disptextp=malloc(sizeof(short)*max_text))==NULL ){
  148.             mesout(MEMORY_ERROR);
  149.             MOS_end();
  150.             exit(0);
  151.         }
  152.         if ( (disp_title=malloc(sizeof(void *)*max_title))==NULL ){
  153.             mesout(MEMORY_ERROR);
  154.             MOS_end();
  155.             exit(0);
  156.         }
  157.         for (i=0;i<max_title;i++){
  158.             if ( (disp_title[i]=malloc(sizeof(char)*90))==NULL ){
  159.                 mesout(MEMORY_ERROR);
  160.                 MOS_end();
  161.                 exit(0);
  162.             }
  163.         }
  164.  
  165.         logFp=fopen( logfile, "rb" );
  166.         if ( logFp == NULL ) {
  167.             mesout ( FILE_ERROR );
  168.             MOS_end();
  169.             exit(0);
  170.         }
  171.  
  172.         MOS_sysIcon(82,16,16,0);
  173.         MOS_color( 0,12 );
  174.         MOS_setpos(320,200);
  175.         MOS_disp(1);
  176.         EGB_writePage(egbwork,0);
  177.         EGB_color(egbwork, 0, TEXT_COL);
  178.         linedsp(256,290,file_read_mes);
  179.  
  180.         logtextleng=fread(logtext,1,logtextleng,logFp);
  181.         fclose ( logFp );
  182.         for (i=0;i<15;i++) logtext[logtextleng+i]=0x00;
  183.  
  184.         MOS_sysIcon(170,0,0,0);
  185.         MOS_disp(0);
  186.         MOS_color( 0,ARROW_COL );
  187.         EGB_color(egbwork, 0, BACK_COL);
  188.         EGB_clearScreen(egbwork);
  189.         EGB_color(egbwork, 0, TEXT_COL);
  190.  
  191.         EGB_writePage(egbwork,0);
  192.  
  193.         if (logcheck(logtext,logtextleng,disp_title,intext,disptextn) != 0){
  194.             if (dispmode==NORMAL_MODE){
  195.                 disptext=disptextn;
  196.                 max_text=max_textn;
  197.             }
  198.             else{
  199.                 parmode(intext,disptextp);
  200.                 parmodedone=1;
  201.                 for (i=0;i<max_textp;i++)
  202.                     if(intext->text[disptextp[i]].text.id!=TITLE_ID) break;
  203.                 if (i==0) i=1;
  204.                 disptext=&disptextp[i-1];
  205.                 max_text=max_textp-(i-1);
  206.             }
  207.             textno=0;
  208.             contf=1;
  209.             back=0;
  210.  
  211.             while ( contf ){
  212.  
  213.                     /* text display                     */
  214.  
  215.                 switch(textdsp(logtext,(int)logtextleng,disp_title,intext,
  216.                                                 disptext,&textno)){
  217.                     case 0 :        /* all quit */
  218.                         contf=0;
  219.                         free(logtext);
  220.                         for (i=0;i<max_title;i++) free(disp_title[i]);
  221.                         free(disp_title);
  222.                         free(intext->text);
  223.                         free(intext);
  224.                         free(disptextn);
  225.                         free(disptextp);
  226.                         parmodedone=0;
  227.                         logfile[0]=0x00;
  228.                         break;
  229.                     case 1 :        /* log save & quit */
  230.                         EGB_clearScreen(egbwork);
  231.                         rename(logfile,bupfile);
  232.                         logFp=fopen( logfile, "wb" );
  233.                         if ( logFp == NULL ) {
  234.                             mesout(FILE_ERROR);
  235.                             MOS_end();
  236.                             exit(0);
  237.                         }
  238.                         clearerr(logFp);
  239.                         nowtext=disptext[textno];
  240.                         if(intext->text[nowtext-1].text.id==TITLE_ID){
  241.                             nowtext--;
  242.                         }
  243.                         fwrite((void *)&logtext[intext->text[nowtext].text.pos]
  244.                             ,1,logtextleng-(intext->text[nowtext].text.pos),
  245.                             logFp);
  246.                         if (ferror(logFp)!=0) mesout(FILE_ERROR);
  247.                         fclose(logFp);
  248.                         contf=0;
  249.                         for (i=0;i<max_title;i++) free(disp_title[i]);
  250.                         free(disp_title);
  251.                         free(intext->text);
  252.                         free(intext);
  253.                         free(logtext);
  254.                         free(disptextn);
  255.                         free(disptextp);
  256.                         parmodedone=0;
  257.                         logfile[0]=0x00;
  258.                         strcpy (logfile,filesel());
  259.                         break;
  260.                     case 2 :        /* title mode */
  261.                         EGB_clearScreen(egbwork);
  262.                         titlemod(logtext,(int)logtextleng,
  263.                                         disp_title,intext,disptext,&textno);
  264.                         back=0;
  265.                         break;
  266.                     case 3 :        /* new file select */
  267.                         EGB_clearScreen(egbwork);
  268.                         free(logtext);
  269.                         for (i=0;i<max_title;i++) free(disp_title[i]);
  270.                         free(disp_title);
  271.                         free(intext->text);
  272.                         free(intext);
  273.                         free(disptextn);
  274.                         free(disptextp);
  275.                         parmodedone=0;
  276.                         logfile[0]=0x00;
  277.                         strcpy (logfile,filesel());
  278.                         contf=0;
  279.                         break;
  280.                     case 4 :        /* mode change */
  281.                         nowtext=disptext[textno];
  282.                         EGB_clearScreen(egbwork);
  283.                         EGB_writePage(egbwork,1);
  284.                         box(390,464,440,478,MODE_BACK_COL,1);
  285.                         EGB_color(egbwork, 0, MODE_COL);
  286.                         if (dispmode==NORMAL_MODE){
  287.                             if(parmodedone==0){
  288.                                 parmode(intext,disptextp);
  289.                                 parmodedone=1;
  290.                             }
  291.                             for (i=0;i<max_textp;i++)
  292.                               if(intext->text[disptextp[i]].text.id!=TITLE_ID)
  293.                                             break;
  294.                             if (i==0) i=1;
  295.                             disptext=&disptextp[i-1];
  296.                             max_text=max_textp-(i-1);
  297.                             dispmode=PARENT_MODE;
  298.                             linedsp(391,478,parentmode);
  299.                         }
  300.                         else{
  301.                             dispmode=NORMAL_MODE;
  302.                             disptext=disptextn;
  303.                             max_text=max_textn;
  304.                             linedsp(391,478,normalmode);
  305.                         }
  306.                         EGB_writePage(egbwork,0);
  307.                         EGB_color(egbwork, 0, TEXT_COL);
  308.                         for (textno=max_text-1;textno>0;textno--)
  309.                                 if (nowtext==disptext[textno]) break;
  310.                         back=0;
  311.                         break;
  312.                     case 5 :        /* console */
  313.                         system("f:");
  314.                         system("cd \rbin");
  315.                         system("aricon");
  316.                         initial_panel ( );
  317.                         back=0;
  318.                         break;
  319.                     case 6 :        /* conf title mode */
  320.                         EGB_clearScreen(egbwork);
  321.                         ttitlemod(logtext,(int)logtextleng,
  322.                                         disp_title,intext,disptext,&textno);
  323.                         back=0;
  324.                         break;
  325.                 }
  326.             }
  327.         }
  328.         else{
  329.             mesout( LOG_ERROR );
  330.             EGB_clearScreen(egbwork);
  331.             free(logtext);
  332.             for (i=0;i<max_title;i++) free(disp_title[i]);
  333.             free(disp_title);
  334.             free(intext->text);
  335.             free(intext);
  336.             free(disptextn);
  337.             free(disptextp);
  338.             parmodedone=0;
  339.             logfile[0]=0x00;
  340.             strcpy (logfile,filesel());
  341.         }
  342.     }
  343.     MOS_end();
  344.     exit(0);
  345. }
  346.  
  347. /*
  348.     initial set
  349. */
  350.  
  351. void    initial(void)
  352. {
  353. union    REGS    in;
  354. struct    SREGS    seg;
  355.  
  356.                             /* initialization            */
  357.  
  358.                             /* key board initialize */
  359.  
  360.     in.h.ah = 0x05;
  361.     in.h.al = 0x01;
  362.     intreal(0x90, &in, &in, &seg);
  363.  
  364.     set24h ( );
  365.  
  366.     EGB_init(egbwork,EGBWorkSize);
  367.     EGB_resolution(egbwork,0,3);
  368.     EGB_resolution(egbwork,1,3);
  369.  
  370.                             /* screen initialize        */
  371.     EGB_textZoom(egbwork,0,8,16);
  372.     EGB_textZoom(egbwork,1,16,16);
  373.  
  374.         /*        mouse initialization        */
  375.     MOS_start(moswork,MosWorkSize);
  376.     MOS_resolution( 0,3 );
  377.     MOS_writePage( 1 );
  378.     MOS_color( 0,ARROW_COL );
  379.  
  380.         /*        sound initialization        */
  381.     SND_elevol_all_mute( 0xff );
  382.     SND_elevol_set( 1, 127, 127 );
  383.  
  384.     initial_panel( );
  385.  
  386.     return;
  387. }
  388.  
  389. /*
  390.     initial display panel set
  391. */
  392.  
  393. void    initial_panel(void)
  394. {
  395.     int        i;
  396.     char    para[150];
  397.     char    *headtitle={"                   file name ="};
  398.     char    *name={"B-Browser  V1.2"};
  399.  
  400.         /*        palette set            */
  401.     EGB_writePage(egbwork,0);
  402.  
  403.     DWORD(para + 0) = palno;
  404.     for (i=0;i<palno;i++){
  405.         DWORD(para + 8*i+4) = colpal[i][0];
  406.         BYTE(para + 8*i+ 8) = colpal[i][3];
  407.         BYTE(para + 8*i+ 9) = colpal[i][1];
  408.         BYTE(para + 8*i+10) = colpal[i][2];
  409.         BYTE(para + 8*i+11) = 0;
  410.         EGB_palette(egbwork,1,para);
  411.     }
  412.     EGB_color(egbwork, 1, BACK_COL);
  413.     EGB_clearScreen(egbwork);
  414.  
  415.     EGB_writePage(egbwork,1);
  416.  
  417.     DWORD(para + 0) = palno;
  418.     for (i=0;i<palno;i++){
  419.         DWORD(para + 8*i+4) = colpal[i][0];
  420.         BYTE(para + 8*i+ 8) = colpal[i][3];
  421.         BYTE(para + 8*i+ 9) = colpal[i][1];
  422.         BYTE(para + 8*i+10) = colpal[i][2];
  423.         BYTE(para + 8*i+11) = 0;
  424.         EGB_palette(egbwork,1,para);
  425.     }
  426.     EGB_color(egbwork, 1, 0);
  427.     EGB_clearScreen(egbwork);
  428.  
  429.     EGB_displayPage(egbwork,1,3);
  430.  
  431.         /*        title display        */
  432.     EGB_writePage(egbwork,1);
  433.     EGB_color(egbwork, 1, 0);
  434.     EGB_clearScreen(egbwork);
  435.     box(0,0,639,34,TITLEBACK_COL,1);
  436.     box(0,462,639,479,TITLEBACK_COL,1);
  437.     EGB_color(egbwork, 0, TITLE_COL);
  438.     linedsp(20,15,headtitle );
  439.     EGB_color(egbwork, 0, NAME_COL);
  440.     EGB_fontStyle(egbwork, 1);
  441.     linedsp(20,15,name );
  442.     EGB_fontStyle(egbwork, 0);
  443.     EGB_color(egbwork, 0, TITLE_COL);
  444.     linedsp(268,15,logfile );
  445.  
  446.         /*        display mode display        */
  447.     EGB_writePage(egbwork,1);
  448.     box(390,464,440,478,MODE_BACK_COL,1);
  449.     EGB_color(egbwork, 0, MODE_COL);
  450.     if (dispmode==NORMAL_MODE) linedsp(391,478,normalmode);
  451.     else linedsp(391,478,parentmode);
  452.  
  453.     EGB_color(egbwork, 0, TEXT_COL);
  454.     EGB_color(egbwork, 1, BACK_COL);
  455.     EGB_writePage(egbwork,0);
  456.     EGB_clearScreen(egbwork);
  457.     return;
  458. }
  459.  
  460.